<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//兑换商品表
class Gift_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'gift';
        $this->gift_category_table = 'gift_category';
    }
    
    function Get($id){
        return $this->db->select('*')->from($this->table)->where('id',$id)->get()->row_array();
    }
    
    function get_list($where,$page,$limit,$like){
        $this->db->select($this->table.'.*,'.$this->gift_category_table.'.title cate_name');
        $this->db->from($this->table);
        $this->db->join($this->gift_category_table,$this->gift_category_table.'.id = '.$this->table.'.cate_id');
        $this->db->where($where);
        if($like){
            $this->db->like($this->table.'.title',$like);
        }
        $this->db->order_by('id','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_count($where,$like){
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where($where);
        if($like){
            $this->db->like($this->table.'.title',$like);
        }
        $query = $this->db->get();
        return $query->num_rows();
    }
    
    //插入数据
    function insert($data)
    {
            $this->db->insert($this->table, $data);
            if($this->db->affected_rows()){
               return $this->db->insert_id();
            }else{
                return 0;
            }
    }
    
    //更新数据
    function update($data,$id)
    {
            return $this->db->where('id',$id)->update($this->table, $data);
    }
    
    //删除数据
    function dalete($delid)
    {	
            $this->db->where('id',$delid);
            $this->db->delete($this->table);
            return $this->db->affected_rows();
    }
    
    //设置状态
    function setstatus($status,$ids)
    {
            return $this->db->where_in('id',$ids)->update($this->table, array('status'=>$status));
    }
    
    //设置状态
    function setindex($index,$ids)
    {
            return $this->db->where_in('id',$ids)->update($this->table, array('is_index'=>$index));
    }
}
